package com.carbohydrate42.kotlin_compose_demo.config

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Lock
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.navigation.NavHost

enum class LayoutEnum(
    val label: String,
    val value: Int
) {
    BlankLayout("blank_layout_page", 0),
    MainPageLayout("main_page_layout", 1),
    SubPageLayout("sub_layout", 2)
}

enum class Router(
    val route: String,
    val title: String = "",
    val icon: ImageVector = Icons.Default.Lock,
    val isShowOnBottomMenu: Boolean = false,
    val layout: LayoutEnum = LayoutEnum.BlankLayout,
    val component: @Composable (NavHost) -> Unit = {}
) {

    // empty page 不要加上title, 否则在跳转到 SubPage 的时候 top bar 里的 title 会抖动一下
    Empty("empty"),
    Page1(
        "page1",
        "Page1",
        isShowOnBottomMenu = true,
        layout = LayoutEnum.MainPageLayout
    ),
    Page2(
        "page2",
        "Page2",
        isShowOnBottomMenu = true,
        layout = LayoutEnum.MainPageLayout
    ),
    Page3(
        "page3",
        "Page3",
        isShowOnBottomMenu = true,
        layout = LayoutEnum.MainPageLayout
    ),

    SubPage1(
        "sub_page1",
        "SubPage1",
        layout = LayoutEnum.SubPageLayout
    ),

    SubPage2(
        "sub_page2",
        "SubPage2",
        layout = LayoutEnum.SubPageLayout
    ),

    BlankLayoutPage(
        "empty_layout_page",
        "BlankLayoutPage",
        layout = LayoutEnum.BlankLayout
    )

    ;

    companion object {
        fun fromRoute(route: String?): Router {
            for (routerEnum in values()) {
                if (routerEnum.route == route) {
                    return routerEnum
                }
            }
            return Empty
        }

        fun isBlankLayout(router: Router): Boolean {
            return router.layout == LayoutEnum.BlankLayout
        }

        fun isMainPageLayout(router: Router): Boolean {
            return router.layout == LayoutEnum.MainPageLayout
        }

        fun isSubPageLayout(router: Router): Boolean {
            return router.layout == LayoutEnum.SubPageLayout
        }

        fun getAllShouldShowBottomMenuRouters(): List<Router> {
            return values().filter { it.isShowOnBottomMenu }
        }
    }
}